const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    balance: '14118.80',
  
    hostUrl:app.globalData.hostUrl
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {
    var that = this;

    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    that.lvjuka();
  },
  lvjuka:function(){
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'User/lvjuka',
      data: {
        // opt: 'getUser',
        userId:wx.getStorageSync('userId'),
        type: that.data.currentTab

      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res, '用户信息')
        if (res.data != null) {
          that.setData({
            info: res.data,
          })

        }
      }

    })
  },
  /** 
   * 滑动切换tab 
   */
  // bindChange: function(e) {
  //   var that = this;
  //   that.setData({
  //     currentTab: e.detail.current
  //   });
  //   that.lvjuka();
  // },
  /** 
   * 点击tab切换 
   */
  swichNav: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    that.lvjuka();
  },
  zhanghu: function() {
    wx.navigateTo({
      url: '../zhanghu',
    })
  },
  //微信支付
  pay: function (e) {//支付
    console.log(e)
    // var payway=r.

    var that = this;
    if (e.currentTarget.dataset.payway == 2) {
      wx.request({
        url: app.globalData.apiUrl + 'Pay/lvju_GetUnifiedOrderResult',
        data: {
          // opt: 'GetUnifiedOrderResult',
          userId: wx.getStorageSync('userId'),
          id: e.currentTarget.dataset.orderid,//订单id
          // typeId: 2,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res, '支付返回信息')
          // return ;
          wx.requestPayment({
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr,
            'package': res.data.package,
            'signType': 'MD5',
            'paySign': res.data.paySign,
            'success': function (res) {
              console.log(res)
              that.onLoad();
            },
            'fail': function (res) {
              that.onLoad();

            },
            'complete': function (res) {
              that.onLoad();

            }
          })

        }
      })
    } else {
      wx.navigateTo({
        url: '../../new_inter/zhifu/zhifu?orderid=' + e.currentTarget.dataset.orderid + '&type=""',
      })
    }

  },
  //去使用
  use:function(e){
    wx.navigateTo({
      url: '../../new_inter/hotel_order/hotel_order?OrderCode=' + e.currentTarget.dataset.orderid ,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function() {

  // }
})